/*
    登录页面 验证与跳转
*/

function  userLogin() {
    var account = $("#inputUsername").val();//账号
    var password = $("#inputPassword").val();//密码
    var lazy = $("#chk11").prop("checked");//是否自动登录

    if (account == '') {
        $(".alert").addClass("alert alert-danger").show();
        $("#alert").html("请输入账号!");
    } else if (password == '') {
        $(".alert").addClass("alert alert-danger").show();
        $("#alert").html("请输入密码!");
    } else{
        $.ajax({
            type: 'post',
            url: "http://139.196.28.69:3000/userlogin",
            data: { id: account, pass: password },
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.ret == 1) {
                    if (lazy) {
                        localStorage["RKname"] = account;
                        localStorage["RKpass"] = password;
                        localStorage["RKlazy"] = lazy;
                    }
                    localStorage["RKtoken"] = data.data;
                    jump('index.html');

                } else {
                    alert(data.msg);//错误信息
                }

            }, error: function (XMLResponse) {
                console.log(XMLResponse);
                $(".alert").addClass("alert alert-danger").show();
                $("#alert").html("账号不存在或密码错误！");
            }
        });
    };
};



//b!=1 时 自动登录
if (b != 1) { 
    $("#inputUsername").val(RKname);
    $("#inputPassword").val(RKpass);
    $("#chk11").attr('checked', 'checked');
    var lazy = $("#chk11").is(":checked");
    // alert(lazy)
    
    $("#loginBtn").css({ background: "#9A9A9A", border: "none", color: "#000" }).attr("onclick", "").html("登录中……");
    // $(".alert").removeClass("alert-warning").addClass("alert alert-success").show();
    // $("#alert").html("登录中……");
    $.ajax({
        type: 'post',
        url: "http://139.196.28.69:3000/userlogin",
        data: { id: RKname, pass: RKpass },
        dataType: 'json',
        success: function (data) {
            console.log(data);
            if (data.ret == 1) {
                if (lazy) {
                    localStorage["RKname"] = RKname;
                    localStorage["RKpass"] = RKpass;
                }
                localStorage["RKtoken"] = data.data;
                jump('index.html');
            } else {
                alert(data.msg)
            }
        }, error: function (XMLResponse) {
            console.log(XMLResponse);
        }
    });
}